$(document)
		.ready(
				function() {
					var contextPath = document.location.pathname;
					var index = contextPath.substr(1).indexOf("/");
					contextPath = contextPath.substr(1, index);
					var basePath = "/" + contextPath;
					var totalCount = $("#totalCount").val();
					var pSize = $("#pageSize").val();
					var pageIndex = $("#pageIndex").val();
					var pageCount = $("#pageCount").val();
					var memberId = $("#memberId").val();
					/*alert("totalCount-------->"+totalCount);
					alert("pSize-------->"+pSize);
					alert("pageIndex-------->"+pageIndex);
					alert("pageCount-------->"+pageCount);*/
					$('#pagination3').jqPaginator({
						//totalPages : pageCount,
						totalCounts:totalCount,
						pageSize:pSize,
						visiblePages : pageCount,
						currentPage : 1,
						prev : '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
						page : '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
						next : '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
						onPageChange : function(num, type) {
							$("#pageIndex").val(num);
							var status = $("#status").val();
							var queryUrl = "queryByPage.do";
							$.ajax({
								url : queryUrl,
								dataType : 'json',
								data : {
									memberId:memberId,
									status:status,
									pageIndex : num,
									pageSize : pSize
								},
								cache : false,
								success : function(data) {
									$("#orderList tr:not(:first)").remove();
									var results = data.pageResult.resultList;
									for (i = 0; i < results.length; i++) {
										var order = results[i];
										var detail = order.orderDetail;
										var rowContent = "<tr class='sep_row' id='"
											+ order.id
											+ "'><td colspan='6'></td></tr>" 
											+ "<tr>"
											+ "<td class='alignmentLeft' colspan='6'><div class='divBorder'><table style='width:99%;margin:2px 2px 5px 2px;'><tr><td colspan='5'><span class='desc'>" 
											+ "<input name='orderId' class='checkbox' type='checkbox' value='"
											+ order.id 
											+ "'/></span><span class='m-r-x'>"
											+ order.createOrderTime
											+ "</span><span >订单号："
											+ order.orderCode
											+ "</span></td>"
											+ "<td  class='td-last'><span class='delete'>" 
											+ "<img src="+basePath+"/HRTWEB/images/delete.jpg alt=''/></span></td>"
											+ "</tr>";
										var len = detail.length;
										for(j=0;j<detail.length;j++){
											var tail = detail[j];
											rowContent = rowContent + "<tr class='order_bd'>"
												+"<td class='first baobei'><div class='desc m-b-x'>" 
												+ "<a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="
												+ order.id
												+ "' target='_blank' title='查看宝贝详情' >" 
												+ "<img src="+basePath+"/HRTWEB/images/family.jpg title='查看宝贝详情' alt=''/></a></div>"
												+"<span class='m-l-md myOrder '>" 
												+ "<a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="
												+ order.id
												+ "' target='_blank'>"
												//描述
												+ tail.giftDescr
												+ "</a></span></td>"
												
												+"<td class='td-center price'>"+tail.salePrice+"</td>"
												
												+"<td class='td-center trade_operate'>"+tail.total+"</td>";
											
												if(len>1){
													if(j < 1){
														//总价
														rowContent = rowContent + "<td class='trade_operate td-center' rowspan='"+len+"'>"
															+ order.summery
															+ "</td>"
															//交易状态
															+ "<td class='trade_operate myOrder td-center'  rowspan='"+len+"'><span>";
															if (order.status == 0) {
																rowContent = rowContent
																		+ "已下单";
															} else if (order.status == 1) {
																rowContent = rowContent
																		+ "已付款";
															} else if (order.status == 2) {
																rowContent = rowContent
																		+ "已发货";
															} else if (order.status == 3) {
																rowContent = rowContent
																		+ "已收货";
															} else if (order.status == 4) {
																rowContent = rowContent
																		+ "已确认";
															} else if (order.status == 5) {
																rowContent = rowContent
																		+ "申请退货";
															} else if (order.status == 6) {
																rowContent = rowContent
																		+ "已退货";
															} else {
																rowContent = rowContent
																		+ "已退款";
															}
															rowContent=rowContent+"</span><br/><span><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>订单详情</a></span> </td>";
															//交易状态结束
															
															//交易操作
															rowContent = rowContent+ "<td class='td-last myOrder trade_operate' rowspan='"+len+"'>";
															if(order.status==0){
																rowContent = rowContent +
																		"<div><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>前往付款</a></div>";
															}
															if(order.status==1){
																rowContent = rowContent +
																		"<div><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>催单</a></div>";
															}
															if(order.status==2){
																rowContent = rowContent +
																		"<div><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>确认收货</a></div>";
															}
															if(order.status==5){
																rowContent = rowContent +
																		"<div><a href='javascript:;' name='delBtn' id='delBtn' objId='"+ order.id+ "'>删除</a></div>";
															}
															if(order.isComment==0&&order.status==4){
	
																rowContent = rowContent +
																		"<div><a href='"+basePath+"/web/orderInfor/commentByOrderId.do?orderId="+order.id+"' target='_blank'>评论</a></div>";
															}
															if(order.isComment==1&&order.status<=5){
																rowContent = rowContent +
																		"<div><a href='"+basePath+"/web/orderInfor/commentByOrderId.do?orderId="+order.id+"' target='_blank'>追加评论</a></div>";
															}
															if(order.isView==1){
																rowContent = rowContent+ "<div><a href='javascript:;' name='recoveryBtn' id='recoveryBtn' objId='"+ order.id+ "' >还原订单</a></div>";
																rowContent = rowContent+ "<div><a href='javascript:;' name='destoryBtn' id='destoryBtn' objId='"+ order.id+ "'>彻底删除</div>";
															}
															rowContent = rowContent+ "</td>";

															//交易操作结束
													}
													
												}else{
													//总价
													rowContent = rowContent + "<td class='trade_operate td-center'>"
														+ tail.summery
														+ "</td>"
													//交易状态
														+ "<td class='trade_operate myOrder td-center'><span>";
														if (order.status == 0) {
															rowContent = rowContent
																	+ "已下单";
														} else if (order.status == 1) {
															rowContent = rowContent
																	+ "已付款";
														} else if (order.status == 2) {
															rowContent = rowContent
																	+ "已发货";
														} else if (order.status == 3) {
															rowContent = rowContent
																	+ "已收货";
														} else if (order.status == 4) {
															rowContent = rowContent
																	+ "已确认";
														} else if (order.status == 5) {
															rowContent = rowContent
																	+ "申请退货";
														} else if (order.status == 6) {
															rowContent = rowContent
																	+ "已退货";
														} else {
															rowContent = rowContent
																	+ "已退款";
														}
														rowContent=rowContent+"</span><br/><span><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>订单详情</a></span> </td>";
														//交易状态结束
														
														//交易操作
														rowContent = rowContent + "<td class='trade_operate td-center'>"
														

														if(order.status==0){
															rowContent = rowContent +
															       "<div><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>前往付款</a></div>";
														}
														if(order.status==1){
															rowContent = rowContent +
															      "<div><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>催单</a></div>";
														}
														if(order.status==2){
															rowContent = rowContent +
															      "<div><a href='"+basePath+"/web/orderInfor/queryByOrderId.do?orderId="+order.id+"' target='_blank'>确认收货</a></div>";
														}
														
														if(order.status==5){
															rowContent = rowContent+ 
															     "<div><a href='javascript:;' name='delBtn' id='delBtn' objId='"+ order.id+ "'>删除</a></div>";
														}
														if(order.isComment==0&&order.status==4){
	
															rowContent = rowContent +
															     "<div><a href='"+basePath+"/web/orderInfor/commentByOrderId.do?orderId="+order.id+"' target='_blank'>评论</a></div>";
                                               			}
														if(order.isComment==1&&order.status<=5){

															rowContent = rowContent+
															     "<div><a href='"+basePath+"/web/orderInfor/commentByOrderId.do?orderId="+order.id+"' target='_blank'>追加评论</a></div>";
														}
														if(order.isView==1){
															rowContent = rowContent +
															     "<div><a href='javascript:;' name='recoveryBtn' id='recoveryBtn' objId='"+ order.id+ "' >还原订单</a></div>";
															rowContent = rowContent +
															     "<div><a href='javascript:;' name='destoryBtn' id='destoryBtn' objId='"+ order.id+ "' >彻底删除</a></div>";

														}

														rowContent = rowContent+ "</td>";

														//交易操作结束
												}
												
										}
										rowContent=rowContent+"</tr></table></div></td>";
										$("#orderList").append(rowContent);
									}
	
								},
								error : function(html) {
									return;
								}
							});
						}
					});
					
					
					$("#content").delegate('#more', 'click', function() {
						$("#condition").slideToggle();
					});
					/**
					 * 删除订单
					 */
					$("#content").delegate('#delBtn', 'click', function() {
						var orderId = $(this).attr("objId");
						var delUrl = "delete.do";
						$.ajax({
									url : delUrl,
									dataType : 'text',
									data : {
										orderId:orderId
									},
									cache : false,

									success : function(data) {
										alert(data);
										location.reload();
										
									},
									error : function(html) {
										alert("delete Data failly");
										return;
									}
								});
					});
					/**
					 * 还原订单
					 */
					$("#content").delegate('#recoveryBtn', 'click', function() {
						var orderId = $(this).attr("objId");
						var recoveryUrl = "recovery.do";
						$.ajax({
							url : recoveryUrl,
							dataType : 'text',
							data : {
								orderId:orderId
							},
							cache : false,
							
							success : function(data) {
								alert(data);
								location.reload();
								
							},
							error : function(html) {
								alert("delete Data failly");
								return;
							}
						});
					});
					/**
					 * 彻底删除订单
					 */
					$("#content").delegate('#destoryBtn', 'click', function() {
						var orderId = $(this).attr("objId");
						var recoveryUrl = "destory.do";
						$.ajax({
							url : recoveryUrl,
							dataType : 'text',
							data : {
								orderId:orderId
							},
							cache : false,
							
							success : function(data) {
								alert(data);
								location.reload();
								
							},
							error : function(html) {
								alert("delete Data failly");
								return;
							}
						});
					});
					
					$("#condition").delegate('#actionSearch', 'click', function() {
						alert("查询-----");
					});
					
				});